#include "StdAfx.h"
#include "Login.h"
#include "DlgMain.h"

CDlgLogin::CDlgLogin(void* pController):m_pController(pController)
{
}

//CDlgLogin::~CDlgLogin(void)
//{
//}


LRESULT CDlgLogin::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// center the dialog on the screen
	CenterWindow();

	// set icons
//	HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
//	SetIcon(hIcon, TRUE);
//	HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
//	SetIcon(hIconSmall, FALSE);
	

	return TRUE;
}

LRESULT CDlgLogin::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	EndDialog(IDOK);
	CDlgMain dlg(m_pController);
	return dlg.DoModal();

	// TODO: Add validation code 
	TCHAR szUserName[MAX_UI_TEXT] = {0};
	CUITool::GetItemText(m_hWnd, IDC_USERNAME, szUserName);
	TCHAR szPassword[MAX_UI_TEXT] = {0};
	CUITool::GetItemText(m_hWnd, IDC_PASSWORD, szPassword);

	((CMyController*)m_pController)->Login(m_hWnd, szUserName, szPassword);

//	EndDialog(wID);
//	CDlgMain dlg;
//	return dlg.DoModal();
	return 0;
}

LRESULT CDlgLogin::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	EndDialog(wID);
	return 0;
}


LRESULT CDlgLogin::OnLogin(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	if (wParam > 0)
	{
		EndDialog(IDOK);
		CDlgMain dlg(m_pController);
		return dlg.DoModal();
	}
	else
	{
		// show error message. login failed.
	}
	return 0;
}
